<template>
  <el-dialog v-model="dialogVisible" title="接口说明" height>
    <v-md-editor v-model="text" height="calc(100% - 40px)" :disabled-menus="[]" @upload-image="handleUploadImage" />
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="success">
          确定
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { propTypes } from '@/utils/propTypes'
import * as DebugApi from '@/api/debug'
const emit = defineEmits(['markdownValue'])
const props = defineProps({
  data: propTypes.string.def(''),
})
const dialogVisible = ref(false)

/** 打开弹窗 */
const open = async () => {
  dialogVisible.value = true
  text.value = props.data || ''
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

const text = ref('')

const success = () => {
  dialogVisible.value = false
  emit('markdownValue', text)
}

const handleUploadImage = async (event, insertImage, files) => {
  console.log(files);
  const formData = new FormData();
  formData.append("file", files[0]);
  let res = await DebugApi.uploadPic({ file: files })
  insertImage({ url: res.data });


};


watch(() => props.data,
  () => {
    text.value = props.data
  }, {
  deep: true
})
</script>
